home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / quartz / quartz10.lha / src / runtime / interf.c < prev    next >
C/C++ Source or Header  |  1990-04-29  |  2KB  |  151 lines

  1. /* Grubby interface to Presto -- don't compile with -pg */ 
  2.  
  3. #include <stdio.h>
  4. #include <signal.h>
  5. #include <parallel/microtask.h>
  6. #include "thread.h"
  7. #include "synch.h"
  8. #include <usclkc.h>
  9. #include "quartzcommon.h"
  10. #include "profile.h"
  11. #include "internal.h"
  12.  
  13. int QInit ()
  14.     {
  15.     usclk_init();
  16.     processGroup = getpgrp(0);
  17.  
  18.     ProcessorListInit();
  19.     PrivProcessorInit(0);
  20.     ThreadpoolInit();
  21.     }
  22.  
  23. int QBegin (numProc, numProf, aff)
  24.     int numProc, numProf, aff;
  25.     {
  26.     numProcessors = numProc;
  27.     affinity = aff;
  28.     ProfileInit(numProf);
  29.     ProfileSetAllBusy();
  30.     MFork(ProfileStart, numProc, numProc + numProf, 0);
  31.     }
  32.  
  33. void QProcInit (id)
  34.     int id;
  35.     {
  36.     PrivProcessorInit(id);
  37.     }
  38.  
  39. int QIdleLoopBegin ()
  40.     {
  41.     ReplaceOnIdStack(IdleID, SpinState);
  42.     NowIdle();
  43.     SetProfileOn();
  44.     }
  45.  
  46. int QThreadStart (name, sched)
  47.     char *name;
  48.     int sched;
  49.     {
  50.     register IdStackEntry *s;
  51.     register Thread *t;
  52.     
  53.     if (sched)
  54.         return(0);
  55.     SetStateOverhead();
  56.     ThreadAlloc(t);
  57.     ASSERT(t->type == ThreadType);
  58.     s = pP.thread->idStack.base - 1;
  59.     t->idStack.top = t->idStack.base - 1; 
  60.     while (s < pP.thread->idStack.top)
  61.         (++(t->idStack.top))->procID = (++s)->procID & AllOffMask;
  62.     if (name)
  63.         {
  64.         t->p = SynchInit(name, VarThread);
  65.         TPushOnIdStack(t, t->p, (unsigned int)ReadyState);
  66.         t->p->thread = t;    /* enable profiling of this thread */
  67.         }
  68.     else
  69.         t->p = NULL;
  70.     AddNominal();
  71.     TSetStateReady(t);
  72.     SetStateNormal();
  73.     return((int)t);
  74.     }
  75.  
  76. /* not used yet */
  77. int QThreadReady (thr)
  78.     int thr;
  79.     {
  80.     register Thread *t = thr;
  81.  
  82.     AddNominal();
  83.     TSetStateReady(t);
  84.     }
  85.  
  86. int QThreadIdle (thr)
  87.     int thr;
  88.     {
  89.     register Thread *t = thr;
  90.  
  91.     pP.proc->curThread = pP.thread = pP.idleThread;
  92.     DecNominal();
  93.     NowIdle();
  94.     }
  95.  
  96. int QThreadRun (thr)
  97.     int thr;
  98.     {
  99.     register Thread *t = thr;
  100.  
  101.     pP.proc->curThread = pP.thread = t;
  102.     NowBusy();
  103.     }
  104.  
  105. int QThreadRelease (thr)
  106.     int thr;
  107.     {
  108.     Thread *t = thr;
  109.  
  110.     if (t != 0)
  111.         ThreadFree(t);
  112.     }
  113.  
  114. int QFinish ()
  115.     {
  116.     ProfileFinish();
  117.     }
  118.  
  119. int SLInit (name)
  120.     {
  121.     SpinLock *s;
  122.  
  123.     if (!name)
  124.         return(0);
  125.     s = MyShmalloc(SpinLock, 1);
  126.     SpinLockInit(s, name);
  127.     return((int)s);
  128.     }
  129.  
  130. void SLLock (s)
  131.     {
  132.     if (s)
  133.         SpinLockAcquire((SpinLock *)s);
  134.     }
  135.  
  136. void SLUnlock (s)
  137.     {
  138.     if (s)
  139.         SpinLockRelease((SpinLock *)s);
  140.     }
  141.  
  142. void SLDispose (s)
  143.     {
  144.     if (s)
  145.         {
  146.         SpinLockDispose((SpinLock *)s);
  147.         shfree((char *)s);
  148.         }
  149.     }
  150.  
  151.